﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DomainDriver.CommonUtilities.Enums;
using DomainDriver.DomainModeling.Constraints;
using DomainDriver.DomainModeling.DataProviders;
using DomainDriver.DomainModeling.Exceptions;
using DomainDriver.DomainModeling.Repositories;
using DomainDriver.DomainModeling.Example;
using DomainDriver.DomainModeling.Example.DomainObjects;
using DomainDriver.DomainModeling.GenericUnitTesting;
using DomainDriver.DomainModeling.GenericUnitTesting.Constraints;

namespace DomainDriver.DomainModeling.UnitTests.Constraints
{
    [TestFixture(new object[] { DataSourcePersistenceType.None })]
    [TestFixture(new object[] { DataSourcePersistenceType.File })]
    [TestFixture(new object[] { DataSourcePersistenceType.Database })]
    public class SingletonDomainObjectParentConstraintTests : ParentChildConstraintTestFixture<ExampleDomainModel, EnumerationValue, Guid, EnumerationDomainObject, SingletonDomainObject>
    {
        private int m_NumberOfEnumValuesUsed = 0;

        public SingletonDomainObjectParentConstraintTests(DataSourcePersistenceType persistenceType)
            : base(persistenceType)
        {
            // do nothing
        }

        public override void SetUp()
        {
            base.SetUp();

            m_NumberOfEnumValuesUsed = 0;
        }

        protected override ExampleDomainModel CreateDomainModel(DataSourcePersistenceType persistenceType, bool buildModelWithConstraints)
        {
            ExampleDomainModel model = new ExampleDomainModel(persistenceType, buildModelWithConstraints);
            return model;
        }

        protected override EnumerationDomainObject CreateParent(ref bool parentAlreadyAdded)
        {
            parentAlreadyAdded = true;
            int intValue = (int)EnumerationValue.Option1 + m_NumberOfEnumValuesUsed;
            m_NumberOfEnumValuesUsed++;
            EnumerationValue enumValue = (EnumerationValue)intValue;
            EnumerationDomainObject domainObject = ParentRepository.Read(enumValue);
            return domainObject;
        }

        protected override EnumerationDomainObject CreateFakeParent()
        {
            int fakeEnumValue = EnumUtilities.GetMaxEnumValue<EnumerationValue>() + 1;
            EnumerationDomainObject falseDomainObject = new EnumerationDomainObject(fakeEnumValue, 0);
            return falseDomainObject;
        }

        protected override SingletonDomainObject CreateChild()
        {
            SingletonDomainObject singleton = new SingletonDomainObject();
            return singleton;
        }

        protected override void AssignParentToChild(EnumerationValue parentKey, SingletonDomainObject child)
        {
            child.SelectedEnumerationDomainObjectId = parentKey;
        }
    }
}